<%@ page import="Note.vo.Page" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 王宇航
  Date: 2022/4/16
  Time: 16:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css" type="text/css"/>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
<head>
    <title>Title</title>
</head>
<body>
<script>
function deleteUser(id){
if (confirm("确定删除吗?")){
location.href="${pageContext.request.contextPath}/DeleteUserServlet?id="+id;
}
}</script>
<form action="${pageContext.request.contextPath}/QueryUserByPageServlet" class="form-inline">
    <ul class="nav  nav-tabs">
        <li role="presentation" class="active"><a href="#">主页</a></li>
        <li role="presentation"><a href="${pageContext.request.contextPath}/QueryUserServlet">显示所有用户</a></li>
       <%-- <li role="presentation"><a href="${pageContext.request.contextPath}/user/insertNotes.jsp">添加留言</a>--%>
        <li role="presentation"><img src="../images/${requestScope.imageSrc}" alt="加载中" title="头像" width="32" height="32"></li>
        <li role="presentation" class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
               ${sessionScope.name} <span class="caret"></span>
            </a>
            <ul class="dropdown-menu">
                <li role="presentation" ><a href="${pageContext.request.contextPath}/admin/updateImage.jsp">修改头像</a></li>
            </ul>
        </li>
        <li role="presentation" ><a href="${pageContext.request.contextPath}/quitServlet?id=1"><img src="../images/quit.png" width="23" height="23" alt="退出" title="退出"></a></li>
    </ul>
    <h1 style="color: chocolate" align="center">用户管理
    </h1><br><h4 style="color: chocolate" align="center">
    <c:if test="${applicationScope.allUser!=null}">
        在线人数:${applicationScope.allUser.size()}<br>[
        <c:forEach var="user" items="${applicationScope.allUser}">
            ${user}
        </c:forEach>]
    </c:if>
</h4><br>
    <p align="center">
        <label>Account</label><input type="text" name="account" class="form-control" value="${condition.account[0]}">
        <label>Email</label><input type="text" name="email" class="form-control" value="${condition.email[0]}">
        &nbsp;<button id="search" type="submit" class="btn btn-default">搜索</button>
    </p>
</form>
<table class="table table-bordered table-striped table-hover">
    <tr style="background: skyblue" class="success">
        <th >ID</th>
        <th >Account</th>
        <th>Email</th>
        <th >Identity</th>
        <th>Operate</th>
    </tr>

    <c:forEach var="user" items="${requestScope.page.users}" varStatus="id" >
    <tr>
        <td>${id.count}
        </td>
        <td>${user.account}
        </td>
        <td>${user.email}
        </td>
    <c:if test="${user.flag==0}">
        <td>用户</td>
    </c:if>
        <c:if test="${user.flag==1}">
            <td>管理员</td>
        </c:if>
        <td><a href="javascript:deleteUser(${user.id})"><img src="../images/delete.png" alt="" title="删除"></a>
        </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="5">
            <div style="float: right">
                <c:set var="p" value="${requestScope.page}"></c:set>
              <c:choose>
                  <c:when test="${p.currentPage==1 && p.currentPage==p.totalPage}">
                      <a href="">首页</a>
                      <a href="">上一页</a>
                      <a href="">下一页</a>
                      <a href="">尾页</a>
                  </c:when>
                  <c:when test="${p.currentPage==p.totalPage}">
                      <a href="${pageContext.request.contextPath}/QueryUserByPageServlet?currentPage=1&account=${condition.account[0]}&email=${condition.email[0]}">首页</a>
                      <a href="${pageContext.request.contextPath}/QueryUserByPageServlet?currentPage=${p.currentPage-1}&account=${condition.account[0]}&email=${condition.email[0]}">上一页</a>
                      <a href="">下一页</a>
                      <a href="${pageContext.request.contextPath}/QueryUserByPageServlet?currentPage=${p.totalPage}&account=${condition.account[0]}&email=${condition.email[0]}">尾页</a>
                  </c:when>
                  <c:when test="${p.currentPage==1}">
                      <a href="${pageContext.request.contextPath}/QueryUserByPageServlet?currentPage=1&account=${condition.account[0]}&email=${condition.email[0]}">首页</a>
                      <a href="">上一页</a>
                      <a href="${pageContext.request.contextPath}/QueryUserByPageServlet?currentPage=${p.currentPage+1}&account=${condition.account[0]}&email=${condition.email[0]}">下一页</a>
                      <a href="${pageContext.request.contextPath}/QueryUserByPageServlet?currentPage=${p.totalPage}&account=${condition.account[0]}&email=${condition.email[0]}">尾页</a>
                  </c:when>
                  <c:otherwise>
                      <a href="${pageContext.request.contextPath}/QueryUserByPageServlet?currentPage=1&account=${condition.account[0]}&email=${condition.email[0]}">首页</a>
                      <a href="${pageContext.request.contextPath}/QueryUserByPageServlet?currentPage=${p.currentPage-1}&account=${condition.account[0]}&email=${condition.email[0]}">上一页</a>
                      <a href="${pageContext.request.contextPath}/QueryUserByPageServlet?currentPage=${p.currentPage+1}&account=${condition.account[0]}&email=${condition.email[0]}">下一页</a>
                      <a href="${pageContext.request.contextPath}/QueryUserByPageServlet?currentPage=${p.totalPage}&account=${condition.account[0]}&email=${condition.email[0]}">尾页</a>
                  </c:otherwise>
              </c:choose>
                <%Page p= (Page) request.getAttribute("page");%>
                <select name="currentPage" id="Select" onchange="window.location=this.value">
                <%for (int i = 1; i <= p.getTotalPage(); i++) {%>
                <option value="/QueryUserByPageServlet?currentPage=<%=i%>&account=${condition.account[0]}&email=${condition.email[0]}"
                        <%=(p.getCurrentPage() == +i) ? "selected='selected'" : ""%>>
                    <%=i%>/${requestScope.page.totalPage}
                </option>
                <%}%>
            </select><br>
                第${p.currentPage}页,共${p.totalPage}页,
                ${p.totalCount}条数据
            </div>
        </td>
    </tr>
</table>
<script>
    function selectPage() {
        var num = $("#select").val();
        window.location.href = "/QueryUserByPageServlet?currentPage=" + num;
    }
</script>
</body>
</html>
